<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>


<!DOCTYPE html>
<html>
<head id="MyHead">
    <script src="/resources/Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="/resources/Scripts/jquery.easyui.min-1.3.5.js" type="text/javascript"></script>
        <script src="/resources/Scripts/jquery.datagrid.js" type="text/javascript"></script>
    <script src="/resources/Scripts/JScriptIndex.js" type="text/javascript"></script>
    <script src="/resources/Res/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <link href="/resources/Content/Default.css" rel="stylesheet" type="text/css" />
    <link href="/resources/Content/IndexStyle.css" rel="stylesheet" type="text/css" /> 
        <link href="/resources/Res/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
        <script src="/resources/Res/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <link href="/resources/Res/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <title>
	
    短信管理

</title>
     <script type="text/javascript" language="javascript">
         $(function () {
             $.extend($.fn.datagrid.methods, {
                 addToolbarItem: function (jq, items) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         if (!toolbar.length) {
                             toolbar = $("<div class=\"datagrid-toolbar\"><table cellspacing=\"0\" cellpadding=\"0\"><tr></tr></table></div>").prependTo(dpanel);
                             $(this).datagrid('resize');
                         }
                         var tr = toolbar.find("tr");
                         for (var i = 0; i < items.length; i++) {
                             var btn = items[i];
                             if (btn == "-") {
                                 $("<td><div class=\"datagrid-btn-separator\"></div></td>").appendTo(tr);
                             } else {
                                 var td = $("<td></td>").appendTo(tr);
                                 var b = $("<a href=\"javascript:void(0)\"></a>").appendTo(td);
                                 b[0].onclick = eval(btn.handler || function () { });
                                 b.linkbutton($.extend({}, btn, {
                                     plain: true
                                 }));
                             }
                         }
                     });
                 },
                 removeToolbarItem: function (jq, param) {
                     return jq.each(function () {
                         var dpanel = $(this).datagrid('getPanel');
                         var toolbar = dpanel.children("div.datagrid-toolbar");
                         var cbtn = null;
                         if (typeof param == "number") {
                             cbtn = toolbar.find("td").eq(param).find('span.l-btn-text');
                         } else if (typeof param == "string") {
                             cbtn = toolbar.find("span.l-btn-text:contains('" + param + "')");
                         }
                         if (cbtn && cbtn.length > 0) {
                             cbtn.closest('td').remove();
                             cbtn = null;
                         }
                     });
                 }
             });
         });
    </script>
    
    
                                       <script src="/resources/Res/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
                                         
    <script type="text/javascript" language="javascript">
        $(function () {

            $('#flexigridData').datagrid({
                title: '短信管理', //列表的标题
                iconCls: 'icon-site',
                width: 'auto',
                height: 'auto',
                nowrap: false,
                striped: true,
                collapsible: true,
                url: 'getSMMsgList/0', //获取数据的url
                sortName: 'msgId',
                sortOrder: 'desc',
                idField: 'msgId',

                toolbar: [
                     {
                         text: '查询',
                         iconCls: 'icon-search',
                         handler: function () {
                             flexiQuery();
                         }
                     },
                     {
                        text: '详细',
                        iconCls: 'icon-search',
                        handler: function () {
                            return getView();
                        }
                    }, {
                        text: '创建',
                        iconCls: 'icon-add',
                        handler: function () {
                            return flexiCreate();
                        }
                    },  {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: function () {
                            return flexiDelete();
                        }
                    }, {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            return flexiModify();
                        }
                    }, {
                        text: '发送短信',
                        iconCls: 'icon-search',
                        handler: function () {
                            return SelStudent();
                        }
                    }],
                columns: [[   
                            {field:'msgId',title:'数据',width:150,hidden:'true'},
                    { field: 'msgCode', title: '<label for="msgCode">短信编号</label>', width: 200 }
					,{ field: 'msgTitle', title: '<label for="msgTitle">短信标题</label>', width: 200 }
					,{ field: 'msgContent', title:  '<label for="msgContent">短信内容</label>', width: 335 }
					,{ field: 'msgCreateDate', title:  '<label for="msgCreateDate" >创建时间</label>', width: 135
						, formatter: function (value, rec) {
	                        if (value) {
	                            return dateConvert(value);
	                        } 
	                    }	
					}
					,{ field: 'msgSender', title:  '<label for="msgSender">创建人</label>', width: 135 }
					,{ field: 'msgEditDate', title:  '<label for="msgEditDate">编辑时间</label>', width: 135
						, formatter: function (value, rec) {
	                        if (value) {
	                            return dateConvert(value);
	                        } 
	                    }
					}
					,{ field: 'msgEditor', title:  '<label for="msgEditor">编辑人</label>', width: 135 }
                ]],
                pagination: true,
                pageSize: 10,
                rownumbers: true

            });

             var parent = window.dialogArguments; //获取父页面
            if (parent == "undefined" || parent == null) {
                //    不是在iframe中打开的
            } else {
                //隐藏所有的按钮和分隔符
                $(".l-btn.l-btn-plain").hide();
                $(".datagrid-btn-separator").hide();
                //添加选择按钮
                $('#flexigridData').datagrid("addToolbarItem", [{ "text": "选择", "iconCls": "icon-ok", handler: function () { flexiSelect(); } }]);
            }
        });

        //选择学员
        function SelStudent() {


            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                //window.location.href = "/resources/S_Should/ShouldList/" + arr[0].PK_ID;
                window.parent.showMyWindow("选择学员", "/Message/SelectPerson/" + arr[0].msgId + "?rd=" + Math.random(), 1000, 650, true, false, true);

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        }

        //“查询”按钮，弹出查询框
        function flexiQuery() {
            $('#divQuery').dialog({          
                buttons: [{
                    text: '查询',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //执行查询                        
                        $('#flexigridData').datagrid('reload', { 
                        	
                        	msgCode : $('#msgCode').val(),
                        	msgTitle : $('#msgTitle').val(),
                        	CreateTimeStart_Time : $('#CreateTimeStart_Time').val(),
                        	CreateTimeEnd_Time : $("#CreateTimeEnd_Time").val(),
                        	UpdateTimeStart_Time : $('#UpdateTimeStart_Time').val(),
                        	UpdateTimeEnd_Time : $('#UpdateTimeEnd_Time').val()
                        });
                    }
                },
                     {
                         text: '取消',
                         iconCls: 'icon-cancel',
                         handler: function () {
                             $('#divQuery').dialog("close");
                         }
                     }]
            });
            
            $('#divQuery').dialog("open");
        };

        //“选择”按钮，在其他（与此页面有关联）的页面中，此页面以弹出框的形式出现，选择页面中的数据
        function flexiSelect() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].pk_id);
            }
            arr.push("^");
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].msgTitle);
            }
            //主键列和显示列之间用 ^ 分割   每一项用 , 分割
            if (arr.length > 0) {//一条数据和多于一条
                returnParent(arr.join("&")); //每一项用 & 分割
            }
        }
        //导航到查看详细的按钮
        function getView() {

            var arr = $('#flexigridData').datagrid('getSelections');
            //alert(arr[0].msgId); 
            if (arr.length == 1) {
                window.location.href = "SMDetails/" + arr[0].msgId;
               
            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;
        }
        //导航到创建的按钮
        function flexiCreate() {
            window.location.href = "toMsgCreate";
            return false;
        }
        //导航到修改的按钮
        function flexiModify() {

            var arr = $('#flexigridData').datagrid('getSelections');

            if (arr.length == 1) {
                window.location.href = "toMsgEdit/" + arr[0].msgId;

            } else {
                $.messager.alert('操作提示', '请选择一条数据!', 'warning');
            }
            return false;

        };
        //删除的按钮
        function flexiDelete() {

            var rows = $('#flexigridData').datagrid('getSelections');
            if (rows.length == 0) {
                $.messager.alert('操作提示', '请选择数据!', 'warning');
                return false;
            }

            var arr = [];
            for (var i = 0; i < rows.length; i++) {
                arr.push(rows[i].msgId);
            }
           // alert(arr);
            $.messager.confirm('操作提示', "确认删除这 " + arr.length + " 项吗？", function (r) {
                if (r) {
                    $.post("msgDelete", { query: arr.join(",") }, function (res) {
                        if (res == "OK") {
                           //移除删除的数据

                            $.messager.alert('操作提示', '删除成功!', 'info');
                            $("#flexigridData").datagrid("reload");
                            $("#flexigridData").datagrid("clearSelections");
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                               $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });

        };

    </script>

      <base target = "_self">
</head>
<body class="easyui-layout" style="padding:3px;">
    <table id="flexigridData" fit="true">
    </table>
    
    <div id="divQuery" title="查询列表" class="easyui-dialog" closed="true" modal="false"
        iconcls="icon-search">
         
            <div class="input">
                <div class="editor-label-search">
                    <label for="msgCode">短信编号</label>
                </div>
                <div class="editor-field-search">
                    <input type='text' id='msgCode' name="msgCode"/>
                </div>
            </div>
            <div class="input">
                <div class="editor-label-search">
                    <label for="msgTitle">短信标题</label>
                </div>
                <div class="editor-field-search">
                    <input type='text' id='msgTitle' name=""msgTitle/>
                </div>
            </div> 
            <br style="clear: both;" />
            <div class="editor-label-search">
                <label for="msgCreateDate">创建时间</label>
            </div>
            <div class="editor-field-to">
                <input type="text" id="CreateTimeStart_Time" name="CreateDateStart_Time" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'CreateTimeEnd_Time\');}'})"  />
                到
                <input type="text" id="CreateTimeEnd_Time" name="CreateDateEnd_Time" onclick="WdatePicker({minDate:'#F{$dp.$D(\'CreateTimeStart_Time\');}'})" />
            </div> 
            <br style="clear: both;" />
            <div class="editor-label-search">
                <label for="msgEditDate">编辑时间</label>
            </div>
            <div class="editor-field-to">
                <input type="text" id="UpdateTimeStart_Time" name="UpdateDateStart_Time" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'UpdateTimeEnd_Time\');}'})"  />
                到
                <input type="text" id="UpdateTimeEnd_Time" name="UpdateDateEnd_Time" onclick="WdatePicker({minDate:'#F{$dp.$D(\'UpdateTimeStart_Time\');}'})" />
            </div>
    </div>
	
</body>
</html>
